Quantitative Metabarcoding

Author

Gled Guri

Published

March 14, 2025

If you end up using any of the following model please cite Guri et al., 2024 for models 1 and 2. For models 3 - 5 please cite Guri et al., 2024

This package is designed to simplify complex mathematical processes, allowing researchers, resource managers, and technicians to analyze environmental DNA (eDNA) data without needing advanced mathematical expertise. By using Bayesian inference, the package helps estsimate eDNA concentration from field samples. This package is currently in beta development, and new features and improved documentation are ongoing. Please feel free to reach out with any questions or feedback.

This package includes 5 models that can be used individually or joined within 3 frames of inferences:
1. qPCR (M1 & M2)
2. Metabarcoding (M3 & M4)
3. qPCR + Metabarcoding (M5 which jointly estimates M1-M4)

Directed Acyclic Graph (DAG) of the model overview

QM model overview

First things first, load the package and its dependencies.

devtools::install_github("gledguri/QM",dependencies = TRUE, force = T )
library(QM)
load_QM_packages()

You can load your data but I have included a set of data in the package to work and play with.

# data(herring_qpcr);force(herring_qpcr) #extra data to play around with
data(cod_qpcr);force(cod_qpcr)
data(metabarcoding);force(metabarcoding)

Let’s view the data

cod_qpcr
# A tibble: 403 × 7
   Well  Sample_name Species         Sample_type Ct          Plate   Std_concentration
   <chr> <chr>       <chr>           <chr>       <chr>       <chr>               <dbl>
 1 A1    Std-CH1     Clupea harengus STANDARD    20.67928886 Plate_B           1000000
 2 B1    Std-CH2     Clupea harengus STANDARD    24.28047562 Plate_B            100000
 3 C1    Std-CH3     Clupea harengus STANDARD    27.46961784 Plate_B             10000
 4 D1    Std-CH4     Clupea harengus STANDARD    30.63396072 Plate_B              1000
 5 E1    Std-CH5     Clupea harengus STANDARD    34.198452   Plate_B               100
 6 F1    Std-CH6     Clupea harengus STANDARD    36.77652359 Plate_B                10
 7 G1    Std-CH7     Clupea harengus STANDARD    39.35696793 Plate_B                 1
 8 A2    Std-CH1     Clupea harengus STANDARD    20.85572815 Plate_B           1000000
 9 B2    Std-CH2     Clupea harengus STANDARD    24.01898384 Plate_B            100000
10 C2    Std-CH3     Clupea harengus STANDARD    27.45393944 Plate_B             10000
# ℹ 393 more rows
metabarcoding
# A tibble: 10 × 93
   Species                      sp_idx ini_conc Mock_1 Mock_2 Mock_3 Mock_4 Mock_5 Mock_6 `2019629_11` `2019629_15` `2019629_16` `2019629_22` `2019629_28` `2019629_31` `2019629_32` `2019629_6` `2019629_7` `2020620_03` `2020620_04` `2020620_05` `2020620_06` `2020620_07` `2020620_08` `2020620_11` `2020620_12` `2020620_13` `2020620_14` `2020620_15` `2020620_16` `2020620_19` `2020620_20` `2020620_21` `2020620_22` `2020620_23` `2020620_24` `2020620_27` `2020620_28` `2020620_29` `2020620_30` `2020620_31` `2020620_32` `2021624_10` `2021624_11` `2021624_14` `2021624_15` `2021624_16` `2021624_17` `2021624_18` `2021624_19` `2021624_20` `2021624_21` `2021624_22` `2021624_25` `2021624_26` `2021624_27` `2021624_28` `2021624_29` `2021624_3` `2021624_30` `2021624_31` `2021624_32` `2021624_33` `2021624_36` `2021624_37` `2021624_38` `2021624_39` `2021624_4` `2021624_40` `2021624_41` `2021624_42` `2021624_43` `2021624_44` `2021624_5` `2021624_6` `2021624_7` `2021624_8` `2021624_9` `2019629_12` `2019629_13` `2019629_14` `2019629_19` `2019629_20` `2019629_21` `2019629_23` `2019629_24` `2019629_27` `2019629_29` `2019629_3` `2019629_30` `2019629_4` `2019629_5` `2019629_8`
   <chr>                         <int>    <int>  <int>  <int>  <int>  <int>  <int>  <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>       <int>       <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>       <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>       <int>        <int>        <int>        <int>        <int>        <int>       <int>       <int>       <int>       <int>       <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>        <int>       <int>        <int>       <int>       <int>       <int>
 1 Brosme brosme                     1     6022  26537  26282  55800  37606  34698  82587            0            0            0            0            0            2            0           0           6            2         1782            0            2            0            0            0            2            0            2            0            0            2            0            0            2            0            0            0            0            0            2            0            0            0            0           10            2            0            6            0            0            2            0            0            2            0            2            2            4           0           10            0            4            0            2            0            0            0           0            0            0            6            0            0           0           0           0           2           2            0            0            1            0            0            0            7            2            0            0           2            0           0           1           0
 2 Cyclopterus lumpus                2    12061  63611  38494  80634  58797  37921  95245            2            0            0            2            0            0            0           0           0            4            2            0            2            4            0            0            0            6            0            8            0            0            0            0            4            0            0            0            0            2            4            0            0            2            4            0            0            0            2            0            0            0            2            0           12            4            0           10            0           4           22            4           30            2            2           10            2         6444           0            2            0         1114            0            0           0           0           2           8           2            0            3            6            1            3            0           12            1            1            1          18        90138           2           0           4
 3 Hippoglossoides platessoides      3     6812 103953  53527  96043  83638  50442 118507         8214            0            0         6890            2            0            2       13672           4        17624        20868            0         5686        10148         6574          350            0            6        22342            4         7552        24912            0        12842        17432            4           10         9522        34610        10024        27240        22970        10798           28            6        16172            0            0         8272         8308            8        13990            8         4340       244510       360158       113176       477728       233486       25768       510300       240732       543826        63728        85020         3722        20754        40130        3822         4332        15434        99374        30014        23738           0        1580        1512        5490       13680            1        10716        67511        20325         1203            1        13598            2         7871           18       21045        14509           9           6           3
 4 Leptoclinus maculatus             4     3725 228228 124488 237519 194652 107854 256737          160            0            0         6800            0            0            0        5240           0            4          848            0         3274          746            0            0            0            0            0            2            0            0            0            0          254            0            0            0            0            0         3020         5034            0            2            2            2            0            0            0            0            0            0            2            0         1336            0            0         5584            2        2046            0           66         1024            0         2312        18044            2         1430           0          582            0          724            0            0           0         294        3372           2           0            1            5        21640            5            4            2          218            2            1            2        2016        22234        5348           4           0
 5 Mallotus villosus                 5     9816  72751  35851  94465  58157  31141  90112        70304         3100            6            4           10            0           10        1372        6580          242         2040            4          256            0            0          210         5816          436        15670        10472            2          780            4            4        26074         4454        15910         1640         7958         3552        20624         6072            2         3432         4750        26782         1502          496            4            2           14         4004           14            4        48540        10376       239346        39828        12914          12         9548        15520        98442        16534         6886         3704            6         2534          12            4           10        12658            8            6           4        7354        5094          74        3270            5           11           13            3           10            0           11           73            2            6        9830         3047       40385         860         226
 6 Maurolicus muelleri               6     7087  99815  29082 130790 120742  58762 162580            0            0            0            0            2            0            0           0           2            2            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            2            0            0            2            0            0            0            0            0            0            0            0            0            0            0            0            0            2            2           0            0            0            0            0            0            0            0            0           2            0            0            2            0            0           0           0           4           0           0            0            0            1            3            0            0            3            0            0            0           1            0           0           3           1
 7 Myoxocephalus scorpius            7     8908  75120  44139  77521  70449  48500  91900            0            0            0            2            0            0            0           0           0            6            4            0            0            2           10            0            2            2            0            2            0            2            0            0            4            0            0            2            0            0            0            2            2            2            0            4            0            2            0            0            0            2            0            0            4            2            0            2            6           2           14            4           10            0            0            2            0            4           2            2            0           18            0            0           0           0           0           2           0            0            1            2            0            0            0            2            0            0            1           6            3           2           0           0
 8 Pholis gunnellus                  8     4477  66110  36235  58501  52223  38270  75811          100          694            0         2936            2          834            0        9916           0         2446         3070            4         3306         5562         1146            0            0         2218            4         5542         3176            0            0            4          556            0            0         2428            0         9314         1448         2034            4          824         6954           14         2866            0         1702            0            2            0            2            0         1194           14            6         3068          574        2410           16         1388         2508            4         1094         8266         5300         4572           0          734            0         2678            0            0           2         830        1420        7630        1884            0            0            1            0            0            0            0            0            0            1          12            3           1           0           0
 9 Pleuronectes platessa             9     2637  41550  19983  44716  44234  27283  63749            0            0            0            0            0            0            0           0           0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0            0           0            0            0            0            0            0            0            0            0           0            0            0            0            0            0           0           0           0           0           0            0            0            0            0            0            0            0            0            0            0           0            0           0           0           0
10 Zz_Gadus morhua                  10     5942  72763  56460 111345  82212  52685 112193         8514            8         1752         4462         5630         4822        26164       78346       50714        50744        17520         2622        32848        44932         2036          272        22108            0        25250            2            0        25320        16498         1482        12430        20104         7386         3100        12350            0        14652        11836            4        22106         5912        70490         4274         8420        17494         8180            8        25790        12904           14        30104        23940        13508        65144        11634       17790        88546        15530        49048            6        32758          694          186        18264        8326        18766         4664        79992            4         5492        1652       17274        8860        4160       48536            3            6        23677            0            5            0        11638         4592         7772        36686       18466        20476       29841           8           2

Before you run any model

All the models are designed to be run in similar chain operations:

(1) Load model –> (2) Prepare data –> (3) Run model –> (4) Extract output –> (5) Plot output

  1. Load model is a function that load and compile the stan model into your local computer by running load_model('Model number'). All the stan model are located in the github repository under folder Stan. Loading each model takes slightly less than 1 min.
  2. Prepare data are a set of functions that converts the data frame into a list that will be thereafter imputed when running the stan model (step 3). For running this function the data should be formatted in a particular form, distinguishing the different samples and their information. Please use data_example('Model number') or use data(cod_qpcr) or data(metabarcoding) to see the data format for required for running prepare data functions. The output of this function is a list.
  3. Run Stan model is a function that calls the compiled stan model (step 1) and loads the prepared data (step 2) onto the model. The output of this function is a list containing 2 lists ([1] data list (created in step 2) and [2] stan model output). If you are interested in only looking at the output of the model you can pull out the second list output_list[[2]] 4. Extract output are a set of functions that extract the interested parameters from each specific model output (M1 - M5; step 3) hence the functions are tailored for each particular model output and stan model code. To have an overview of all functions please read through this document or check all functions
  4. Plot output are a set of functions that plot the interested parameters from each specific model output (M1 - M5; step 3 and 4) hence the functions are tailored for each particular model output and stan model code. To have an overview of all functions please read through this document or check all functions. These are standard plots I have created but feel free to generate any plot as you see fit; all model outputs can be extracted either by using extract_param(model = output_list[[2]], par = 'parameter_name') or simply by printing out output_list[[2]]

1 Model 1

Before going to load and run Model 1 and 2 here’s a description of the model.
This model implements a two step model (joint model) to estimate the relationship between DNA concentration (C) and qPCR outcomes (Y and Z). The model jointly combines two compartments (eq. 1.1 - 2.3) to estimate DNA concentration using both Ct values (Y) and positive or negative qPCR amplification outcomes (Z). For detailed explanation please read Guri et al., 2024.

In short the presence (Z = 1) or absence (Z = 0) of qPCR amplification in sample \(i\) in technical replicate \(j\) is modeled as a Bernoulli random variable with the probability of amplification \(\theta_i\). The probability of amplification arises from a Poisson process with rate parameter \(\lambda\). The probability of having no amplification events is given by \(e^{-\lambda}\), and thus the probability of positive amplification is \(1-e^{-\lambda}\). We model \(\lambda\) as a function of concentration where \(\lambda = C \cdot \phi\). Hence \(\phi\) is the probability that a single target molecule in reaction will lead to a successful amplification event. In the ideal scenario when only one target molecule is in the reaction and it gets successfully amplified, \(\phi = 1\).

Additionally the second compartment models the observed Ct values (Y) in sample \(i\) in technical replicate \(j\) as random variable drawn from a Normal distribution with mean \(\mu\) and standard deviation \(\sigma\). We model \(\mu\) as a linear function of DNA concentration (C) with intercept and slope \(\beta0\) and \(\beta1\) (Equation 2.2). The standard deviation of the observed Y is an exponential function of DNA concentration with intercept and slope \(\gamma0\) and \(\gamma1\) (Equation 2.3). Note that \(\beta0\) (intercept between Ct and DNA concentration) has subscript \(_p\) meaning that is different for every plate. The reason for having a different \(\beta0\) is due to the qPCR machine being sensitive to external factors hence every qPCR run has a different \(\Delta\)Rn (normalized fluorescence signal).

\[ \Large \begin{aligned} &\textbf{qPCR probability of detection model}\\ Z_{ij} &\sim \text{Bernoulli}(\theta_{i}) && \text{(1.1)} \\ \theta_{i} &= 1 - exp(-C_{i} \cdot \phi) && \text{(1.2)} \\ &\text{}\\ &\textbf{qPCR continuous model}\\ Y_{ij} &\sim \text{Normal}(\mu_{i}, \sigma_{i}) && \text{(2.1)} \\ \mu_{i} &= \beta0_{p} + \beta1 \cdot ln(C_{i}) && \text{(2.2)} \\ \sigma_{i} &= e^{(\gamma0 + \gamma1 \cdot ln(C_{i}))} && \text{(2.3)} \end{aligned} \]

1.1 Load the stan model

M1 <- load_model('M1')

1.2 Prepare the data to be loaded in the model.

The data should be formatted in a particular form. Please use data_example('M1') to see the data format for required for Model 1 or use data(cod_qpcr) to load the data included in the package.

stan_data_M1 <- prep_stan_M1(
   qpcr_data = cod_qpcr %>% filter(Sample_type=="STANDARD"),
   Ct = "Ct",
   standard_concentration = "Std_concentration",
   plate_index = 'Plate')
Plate index matches the total number of plates

1.3 Run the model.

This chunk runs the Bayesian model (eq. 1.1 - 2.3) using rstan where C is the known DNA concentration from the Standard samples, Y is the observed Ct values form the qPCR machine and Z (Z = 1 for positive amplification & Z = 0 for non amplification hence Ct == ‘Undetermined’).

All the unknown parameters of the model (all Greek letters such as \(\phi\), \(\beta0_p\), \(\beta1\), \(\gamma0\), \(\gamma1\), \(\mu\), \(\sigma\), \(\theta\)) are in stan model output and can be extracted by using extract_qpcr_param(model_output) see below. Note that \(\beta0\) (intercept between Ct and DNA concentration) has subscript \(_p\) meaning that is different for every plate. The reason for having a different \(\beta0\) is due to the qPCR machine being sensitive to external factors hence every qPCR run has a different \(\Delta\)Rn (normalized fluorescence signal).

M1_output <- Run_Model(stan_object = M1, stan_data = stan_data_M1)

1.4 Extract outputs

Here is how you extract the important parameter of the model.

extract_qpcr_param(M1_output)
        parameter       mean     se_mean         sd       2.5%        25%        50%        75%      97.5%    n_eff     Rhat
1       logit_phi  3.2509511 0.010260987 0.90744559  1.5602007  2.6147621  3.2233644  3.8605370  5.0730655 7821.012 1.000227
2 beta_0[Plate_B] 40.4320810 0.002912926 0.14733601 40.1386560 40.3359049 40.4331180 40.5288823 40.7255861 2558.345 1.000469
3 beta_0[Plate_D] 40.6090932 0.002985283 0.15335494 40.3032185 40.5086973 40.6090119 40.7099649 40.9123085 2638.909 1.000297
4 beta_0[Plate_E] 40.6074656 0.003058700 0.15419028 40.2998184 40.5072075 40.6088297 40.7108778 40.9130760 2541.208 1.000429
5 beta_0[Plate_F] 40.7567868 0.002961266 0.14884760 40.4555930 40.6600089 40.7577774 40.8545029 41.0536002 2526.555 1.000343
6 beta_0[Plate_G] 40.4675631 0.002926692 0.14797919 40.1675054 40.3710586 40.4685050 40.5652373 40.7581831 2556.509 1.000494
7          beta_1 -1.4206649 0.000227267 0.01102449 -1.4424432 -1.4278816 -1.4207266 -1.4135232 -1.3985188 2353.125 1.000547
8         gamma_0  0.7775147 0.001068404 0.08978515  0.6029325  0.7155156  0.7777803  0.8390892  0.9520496 7062.168 1.000295
9         gamma_1 -0.2328929 0.000184371 0.01363097 -0.2582249 -0.2423479 -0.2331625 -0.2237269 -0.2055337 5465.988 1.000189

1.5 Plot outputs

This chunk extracts the parameters (all Greek letters in eq. 1.1 - 2.3) and plots them in relation to observed values (Ct and Z). Two different plots are generated each representing the two model compartments, the probability of detection model (eq. 1.1 - 1.2) by running plot_qpcr_prob_det(M1_output), and the continuous model (eq. 2.1 - 2.3) by runningplot_qpcr_cont_mod(M1_output).

plot_qpcr_prob_det(M1_output)

plot_qpcr_cont_mod(M1_output)

plot_qpcr_curves(M1_output)

Also I made a custom function that can plot the continuous model having the plates as the facet.

plot_qpcr_cont_mod_plate_specific(M1_output)

2 Model 2

Model 2 builds on Model 1 by incorporating environmental samples (e.g., field-collected data) alongside standard samples. By sharing parameters learned from the standards (e.g., detection probabilities or Ct-concentration relationships with the known DNA concentration), it estimates the DNA concentration (C_est_log) for imputed field samples (Sample_name) with credible intervals (C_est_log_2.5%CI and C_est_log_97.5%CI). The estimated DNA concentration (C_est_log) from environmental samples can be extracted from the model output using extract_est_conc(M2_output) function see here. The mathematical notation is the same as Model 1 where 2 set of equations (eq 1.1 - 2.3) are used, one for standards and one for the unknown environmental samples where the only join information they share are the model parameters (all Greek letter).

2.1 Load the stan model

M2 <- load_model('M2')

2.2 Prepare the data to be loaded in the model.

The data should be formatted in a particular form. Please use data_example('M2') to see the data format for required for Model 2 or use data(cod_qpcr) to load the data included in the package.

stan_data_M2 <- prep_stan_M2(
    qpcr_data = cod_qpcr,
    sample_type = "Sample_type",
    Ct = "Ct",
    sample_name_column = "Sample_name",
    standard_concentration = "Std_concentration",
    plate_index = 'Plate')
Plate index matches the total number of plates

2.3 Run the model.

M2_output <- Run_Model(stan_object = M2, stan_data = stan_data_M2)

2.4 Extract outputs

extract_qpcr_param(M2_output)
        parameter      mean     se_mean          sd       2.5%        25%        50%        75%      97.5%     n_eff      Rhat
1       logit_phi  2.965589 0.007202432 0.932971621  1.2794118  2.2938566  2.9265239  3.5878782  4.8935987 16779.479 0.9998041
2 beta_0[Plate_B] 40.435481 0.002001273 0.126976432 40.1854890 40.3498907 40.4368867 40.5206351 40.6835534  4025.627 1.0003159
3 beta_0[Plate_D] 40.612665 0.001950660 0.132811412 40.3484191 40.5234878 40.6142236 40.7022924 40.8660984  4635.620 1.0004106
4 beta_0[Plate_E] 40.612149 0.002066261 0.133236474 40.3537627 40.5225541 40.6124367 40.7012046 40.8711776  4157.919 1.0002513
5 beta_0[Plate_F] 40.746596 0.001982163 0.128215677 40.4898191 40.6618923 40.7477687 40.8326212 40.9933965  4184.113 1.0003614
6 beta_0[Plate_G] 40.468649 0.001977125 0.127990357 40.2202047 40.3820808 40.4703015 40.5548255 40.7164611  4190.695 1.0002866
7          beta_1 -1.420594 0.000149147 0.009466964 -1.4388479 -1.4269191 -1.4207789 -1.4142710 -1.4020587  4028.975 1.0002459
8         gamma_0  0.686224 0.000482216 0.056199658  0.5757052  0.6484678  0.6851114  0.7239254  0.7976405 13582.643 0.9999096
9         gamma_1 -0.227383 0.000110693 0.012224469 -0.2501710 -0.2357971 -0.2276830 -0.2195036 -0.2022864 12196.161 1.0003159
extract_est_conc(M2_output) %>% as_tibble()
# A tibble: 84 × 5
   sample_index Sample_name C_est_log `C_est_log_2.5%CI` `C_est_log_97.5%CI`
          <dbl> <chr>           <dbl>              <dbl>               <dbl>
 1            1 2019629_11     -0.191             -1.48               0.791 
 2            2 2019629_12     -0.751             -2.89               0.671 
 3            3 2019629_13      1.36               0.276              2.26  
 4            4 2019629_14     -3.36              -7.37              -0.693 
 5            5 2019629_15     -1.36              -3.42               0.0589
 6            6 2019629_16      1.00               0.144              1.75  
 7            7 2019629_19     -0.998             -3.03               0.416 
 8            8 2019629_20     -3.17              -7.30              -0.437 
 9            9 2019629_21     -3.36              -7.41              -0.633 
10           10 2019629_22     -1.02              -2.44               0.0634
# ℹ 74 more rows

2.5 Plot outputs of Model 2

plot_qpcr_curves(M2_output)

plot_qpcr_prob_det(M2_output)

plot_qpcr_cont_mod(M2_output)

You could change the x limits by adding xmin_log and xmax_log arguments. The limits are in \(log_e\) hence xmax_log = \(8 = 3 \cdot 10^3\)

plot_qpcr_cont_mod(M2_output,xmin_log = 0,xmax_log = 8)

plot_qpcr_cont_mod_plate_specific(M2_output)

Here I provide a standard way of plotting the estimated DNA concentration of environmental (field) samples by putting the samples on x-axis and eDNA concentrations on y-axis. All the DNA concentrations at around \(10^{-1.3}\) and very large error bars are basically non-detects indicating that no targeted DNA was found in all technical replicate of the sample.

plot_est_conc(M2_output)

3 Model 3

Here we establish that the number of observed reads (R) of each species \(s\) in sample \(i\) from metabarcoding sequencing is a draw from a Multinomial distribution given the proportions for each species \(\psi\) in each sample and the total number of reads (T) per that sample (eq 3.1). We formulate that \(\psi\) is the softmax transformation of \(\gamma\) the post-PCR log-ratio amplicon abundance (eq 3.2). The post-PCR log-ratio amplicon abundance \(\gamma\), is the known (pre-PCR) log-ratio DNA concentration (\(alr\)) modified by the product of the ratio of amplification efficiencies \(\alpha\) for each taxa and the number of PCR cycles (\(NPCR\)) (eq 3.3).

\[ \Large \begin{align*} R_{is}\ &\sim \text {Multinomial} \left(\psi_{is},\ T_i\right) && \text{(3.1)}\\ {\psi}_{is}&=\frac{e^{{\gamma}_{is}}}{\sum_{i=1}^{I}e^{\gamma_{is}}} && \text{(3.2)} \\ \gamma_{is}&=alr_{is}+\left(NPCR\times\alpha_s\right) && \text{(3.3)} \\ \end{align*} \]

I know that log-ratio hurts people’s brain so here’s a development of the equation 3.3 to put into perspective.

\[ \Large \begin{align*} {\gamma}_{is}&= alr_{is} + NPCR \cdot \alpha \\ ln\left(\frac{\pi_{is}}{\pi_{i,s=\text{ref}}}\right)&= ln\left(\frac{C_{is}}{C_{i,s=\text{ref}}}\right) + NPCR \cdot ln\left(\frac{1 + a_s}{1 + a_{s=\text{ref}}} \right)\\ \underbrace{\frac{\pi_{is}}{\pi_{i,s=\text{ref}}}}_{\text{Post-PCR ratio}} &= \underbrace{\frac{C_{is}}{C_{i,s=\text{ref}}}}_{\text{Pre-PCR ratio}} \cdot \underbrace{\left( \frac{1 + a_s}{1 + a_{s=\text{ref}}} \right)^{NPCR}}_{\text{PCR amplification factor}} \end{align*} \]

where \(\pi / \pi_{\text{ref}}\) is the ratio of post-PCR sequence abundance relative to the reference species, \(C /C_{\text{ref}}\) is the ratio of pre-PCR sequence abundance relative to the reference species, and \(a / a_{\text{ref}}\) is the amplification efficiency relative to the reference species. With so many ratios it is easier to make mistakes, therefore we use their log-ratios (also computationally easier) and annotate these log-ratios with \(\gamma\), \(alr\), and \(\alpha\) respectively, keeping in mind that such ratios are always relative to the reference species.

Since we know the pre-PCR (initial) concentration when using a mock community and we can derive the post-PCR proportions using the model (eq 3.1 - 3.3) we can estimate the amplification efficiency for each species (always) relative to a reference species.

3.1 Load the stan model

M3 <- load_model('M3')

3.2 Prepare the data to be loaded in the model.

The data should be formatted in a particular form. Please use data_example('M3') to see the data format for required for Model 2 or use data(metabarcoding) to load the data included in the package and select the columns that belong to the mock community.

Important! Please assign ‘Zz_’ before the name of the reference species and assign it on the last row on the metabarcoding dataframe.

An additional feature is the alpha magnitude where the user can indicate the standard deviation of a Normal distribution with mean 0 (prior distribution) for \(\alpha\) parameter. This is left on purpose to be adjusted by the users as not all data are similar. On default alpha = 0.1 but to put values in perspective alpha values = |0.1| indicates a 4 fold difference between pre- and post-PCR (typical 40 cycles) relative to the reference species. Typical alpha values for 12S MiFish primers are < |0.03|.

# Trim metabarcoding data only for mock samples
moc_dat <- metabarcoding %>% select(Species,sp_idx,ini_conc,Mock_1:Mock_6)

# # Prepare the data for going into the model
stan_data_M3 <- prep_stan_M3(
    metabarcoding_data = moc_dat,
    mock_sequencing_columns = c('Mock_1','Mock_2','Mock_3','Mock_4','Mock_5','Mock_6'),
    mock_initial_concentration = 'ini_conc',
    species_index = 'sp_idx',
    species_names = 'Species',
    number_of_PCR = 43,
    alpha_magnitude = 0.1)

3.3 Run the model.

M3_output <- Run_Model(stan_object = M3, stan_data = stan_data_M3)

3.4 Extract outputs

These two functions extract the amplification efficiency from the Model 3 (eq 3.3). Note that the values are in additive log-ratios and the reference species = 0. Each alpha value can be interpreted as the log-difference of amplification efficiency of the species relative to the reference species per each PCR cycle. Any negative value would be indicating poorer amplification efficiency than that of the reference species and positive values vice-versa. Let’s say a value -0.015 is indicating that the species is amplifying -0.015 times more ‘inefficient’ per each PCR cycle than that of the reference species.

extract_amp_efficiecy(M3_output)
                        Species sp_idx        alpha alpha_2.5%_CI alpha_97.5%_CI
1                 Brosme brosme      1 -0.014626037  -0.014735060   -0.014517876
2            Cyclopterus lumpus      2 -0.022591810  -0.022691181   -0.022490046
3  Hippoglossoides platessoides      3 -0.002314560  -0.002404272   -0.002225584
4         Leptoclinus maculatus      4  0.030800474   0.030722899    0.030877159
5             Mallotus villosus      5 -0.017324426  -0.017419904   -0.017226634
6           Maurolicus muelleri      6  0.000791383   0.000704796    0.000881262
7        Myoxocephalus scorpius      7 -0.013585538  -0.013682284   -0.013487081
8              Pholis gunnellus      8 -0.002700723  -0.002805368   -0.002596383
9         Pleuronectes platessa      9  0.002551145   0.002439907    0.002665612
10              Zz_Gadus morhua     10  0.000000000   0.000000000    0.000000000
amp_eff_output_extract(M3_output)
                        Species    Pre-PCR   Post-PCR         ALR Post-PCR_est Post-PCR_est_2.5%_CI Post-PCR_est_97.5%_CI
1                 Brosme brosme 0.08923200 0.05556938  0.01337365   0.05556911           0.05550496            0.05562941
2            Cyclopterus lumpus 0.17871590 0.07901771  0.70793133   0.07901652           0.07895807            0.07908050
3  Hippoglossoides platessoides 0.10093796 0.10672923  0.13663999   0.10672840           0.10669376            0.10675610
4         Leptoclinus maculatus 0.05519582 0.24240363 -0.46697893   0.24240621           0.24245402            0.24234101
5             Mallotus villosus 0.14545023 0.08065732  0.50196793   0.08065583           0.08060965            0.08070735
6           Maurolicus muelleri 0.10501282 0.12690236  0.17621634   0.12690252           0.12687837            0.12694038
7        Myoxocephalus scorpius 0.13199579 0.08596141  0.40490397   0.08596148           0.08590758            0.08601885
8              Pholis gunnellus 0.06633870 0.06898988 -0.28309260   0.06898918           0.06892252            0.06905269
9         Pleuronectes platessa 0.03907419 0.05093104 -0.81240387   0.05093085           0.05086721            0.05099994
10              Zz_Gadus morhua 0.08804659 0.10283804  0.00000000   0.10283990           0.10320387            0.10247378

3.5 Plot outputs

plot_amp_eff(M3_output)

4 Model 4

Model 4 is a continuation of Model 3 by incorporating environmental samples (e.g., field-collected data) alongside mock commuinty samples. By sharing the \(alpha\) parameter learned from the mock community, it estimates the DNA concentration (C_est_log) for imputed field samples (Sample_name) with credible intervals (C_est_log_2.5%CI and C_est_log_97.5%CI). The estimated DNA concentration (C_est_log) from environmental samples can be extracted from the model output using extract_est_conc(M2_output) function see here. The mathematical notation is the same as Model 1 where 2 set of equations (eq 1.1 - 2.3) are used, one for standards and one for the unknown environmental samples where the only join information they share are the model parameters (all Greek letter).

4.1 Load the stan model

M4 <- load_model('M4')

4.2 Prepare the data to be loaded in the model.

# Get column names for mock samples and environmental samples
mock_columns <- metabarcoding %>% select(Mock_1:Mock_6) %>% names()
sample_columns <- metabarcoding %>% select(-all_of(mock_columns),-Species,-sp_idx,-ini_conc) %>% names()

# Prepare the data for going into the model
stan_data_M4 <- prep_stan_M4(
    metabarcoding_data = metabarcoding,
    mock_sequencing_columns = mock_columns,
    sample_sequencing_columns = sample_columns,
    mock_initial_concentration = 'ini_conc',
    species_index = 'sp_idx',
    species_names = 'Species',
    number_of_PCR = 43,
    alpha_magnitude = 0.1)
Warning: Using an external vector in selections was deprecated in tidyselect 1.1.0.
ℹ Please use `all_of()` or `any_of()` instead.
  # Was:
  data %>% select(mock_columns)

  # Now:
  data %>% select(all_of(mock_columns))

See <https://tidyselect.r-lib.org/reference/faq-external-vector.html>.
M4_output <- Run_Model(stan_object = M4, stan_data = stan_data_M4)
Warning: There were 1 divergent transitions after warmup. See
https://mc-stan.org/misc/warnings.html#divergent-transitions-after-warmup
to find out why this is a problem and how to eliminate them.
Warning: Examine the pairs() plot to diagnose sampling problems

4.3 Extract outputs

extract_amp_efficiecy(M4_output)
                        Species sp_idx        alpha alpha_2.5%_CI alpha_97.5%_CI
1                 Brosme brosme      1 -0.014636825  -0.014748121   -0.014527232
2            Cyclopterus lumpus      2 -0.022601922  -0.022702689   -0.022501615
3  Hippoglossoides platessoides      3 -0.002323551  -0.002413130   -0.002233071
4         Leptoclinus maculatus      4  0.030790589   0.030710702    0.030866869
5             Mallotus villosus      5 -0.017332939  -0.017430810   -0.017235720
6           Maurolicus muelleri      6  0.000781060   0.000690996    0.000867964
7        Myoxocephalus scorpius      7 -0.013596615  -0.013695724   -0.013499259
8              Pholis gunnellus      8 -0.002710231  -0.002813960   -0.002608052
9         Pleuronectes platessa      9  0.002538545   0.002425008    0.002652124
10              Zz_Gadus morhua     10  0.000000000   0.000000000    0.000000000
amp_eff_output_extract(M4_output)
                        Species    Pre-PCR   Post-PCR         ALR Post-PCR_est Post-PCR_est_2.5%_CI Post-PCR_est_97.5%_CI
1                 Brosme brosme 0.08923200 0.05556938  0.01337365   0.05556484           0.05549926            0.05563021
2            Cyclopterus lumpus 0.17871590 0.07901771  0.70793133   0.07901274           0.07895522            0.07907411
3  Hippoglossoides platessoides 0.10093796 0.10672923  0.13663999   0.10672845           0.10670207            0.10676622
4         Leptoclinus maculatus 0.05519582 0.24240363 -0.46697893   0.24239699           0.24243810            0.24233476
5             Mallotus villosus 0.14545023 0.08065732  0.50196793   0.08065752           0.08060884            0.08070945
6           Maurolicus muelleri 0.10501282 0.12690236  0.17621634   0.12689530           0.12686130            0.12692069
7        Myoxocephalus scorpius 0.13199579 0.08596141  0.40490397   0.08595380           0.08589735            0.08600965
8              Pholis gunnellus 0.06633870 0.06898988 -0.28309260   0.06898768           0.06892868            0.06904682
9         Pleuronectes platessa 0.03907419 0.05093104 -0.81240387   0.05092297           0.05085796            0.05099161
10              Zz_Gadus morhua 0.08804659 0.10283804  0.00000000   0.10287971           0.10325123            0.10251649
extract_ini_prop(M4_output)
                        Species   2019629_11  2019629_12   2019629_13   2019629_14   2019629_15   2019629_16   2019629_19   2019629_20   2019629_21   2019629_22   2019629_23   2019629_24   2019629_27   2019629_28   2019629_29    2019629_3   2019629_30   2019629_31   2019629_32    2019629_4    2019629_5    2019629_6    2019629_7    2019629_8   2020620_03   2020620_04   2020620_05   2020620_06   2020620_07   2020620_08   2020620_11   2020620_12   2020620_13   2020620_14   2020620_15   2020620_16   2020620_19   2020620_20   2020620_21   2020620_22   2020620_23   2020620_24   2020620_27   2020620_28   2020620_29   2020620_30   2020620_31   2020620_32   2021624_10   2021624_11   2021624_14   2021624_15   2021624_16   2021624_17   2021624_18   2021624_19   2021624_20   2021624_21   2021624_22   2021624_25   2021624_26   2021624_27   2021624_28   2021624_29    2021624_3   2021624_30   2021624_31   2021624_32   2021624_33   2021624_36   2021624_37   2021624_38   2021624_39    2021624_4   2021624_40   2021624_41   2021624_42   2021624_43   2021624_44    2021624_5    2021624_6    2021624_7    2021624_8    2021624_9
1                 Brosme brosme 1.402457e-06 0.002168592 3.231388e-06 1.691807e-05 5.925475e-06 9.950137e-05 4.262637e-07 2.602933e-05 0.0009870199 1.226356e-05 4.765610e-04 7.164128e-04 1.381136e-05 3.832834e-05 7.983685e-06 5.575447e-05 9.318256e-07 5.960871e-04 1.019546e-05 2.410352e-06 6.678156e-04 3.013980e-06 1.700347e-04 4.578395e-05 4.899706e-05 6.441975e-02 7.316634e-05 8.003539e-05 4.772773e-06 1.789412e-05 1.091374e-04 1.016421e-04 3.440202e-06 4.265852e-05 9.678288e-07 6.864486e-07 6.476993e-05 1.563617e-05 1.085765e-05 4.001323e-05 9.236607e-06 5.510942e-06 9.922846e-06 3.688306e-06 4.644031e-07 3.842940e-05 4.611455e-06 2.776014e-06 9.054279e-06 9.543389e-06 1.273838e-04 3.190962e-04 2.425132e-05 3.800663e-04 1.346041e-05 0.0009522793 7.070645e-05 1.907384e-05 1.136779e-05 8.732293e-06 6.221171e-07 5.387650e-06 5.207128e-06 2.405418e-05 5.056369e-06 2.747155e-05 7.907904e-07 8.420973e-06 3.761911e-07 2.470392e-05 5.388968e-06 3.807129e-06 2.917378e-06 1.796891e-05 1.037064e-05 9.810835e-06 4.960751e-05 9.389464e-07 6.945614e-06 1.056537e-04 7.374876e-06 9.770911e-06 1.803410e-04 4.940209e-05
2            Cyclopterus lumpus 2.915018e-05 0.002636817 5.619267e-04 1.477079e-04 7.186145e-06 1.278051e-04 6.012140e-05 4.862541e-03 0.0010674531 2.767352e-04 1.155963e-03 4.836925e-04 1.403500e-04 5.088898e-05 6.698806e-05 7.450899e-04 8.298349e-01 4.887389e-05 1.428605e-05 4.293906e-05 2.908964e-05 3.787769e-06 6.324966e-06 1.857915e-02 1.378339e-04 9.432030e-05 9.167877e-05 1.121361e-04 1.627946e-04 2.178357e-05 1.414082e-04 1.064573e-05 4.114683e-03 4.413901e-06 6.940357e-04 7.684797e-07 6.666444e-06 2.153972e-05 1.381089e-05 1.149183e-04 1.126476e-05 7.239046e-06 1.337851e-05 4.769557e-06 1.313862e-04 1.103041e-04 6.117740e-06 3.362456e-06 1.627886e-04 4.217135e-04 3.017857e-06 2.430058e-05 3.272427e-05 1.717183e-04 1.780000e-05 0.0012198279 7.624832e-06 3.767316e-04 1.347849e-05 7.705950e-05 2.276550e-05 5.214927e-07 3.801673e-05 1.080840e-06 2.024798e-04 8.570466e-05 3.180969e-05 9.138755e-05 3.903402e-05 3.465630e-05 9.526903e-04 1.525845e-04 1.881842e-01 2.465645e-05 2.014455e-04 1.279420e-05 1.322152e-02 1.257144e-06 9.016963e-06 1.362471e-04 9.988732e-06 2.061651e-04 1.072861e-03 6.920314e-05
3  Hippoglossoides platessoides 5.471548e-02 0.057467975 9.969492e-01 7.167498e-01 4.152670e-06 6.475310e-05 9.995487e-01 9.769323e-01 0.5467116927 4.427393e-01 5.608520e-01 4.268813e-04 5.280104e-01 3.617666e-04 5.358596e-04 3.688920e-01 5.584609e-02 2.356662e-05 8.036758e-05 8.390855e-05 3.327404e-03 1.387635e-01 6.644493e-05 5.699697e-03 2.649562e-01 4.442926e-01 4.614498e-05 1.419558e-01 1.791156e-01 6.851477e-01 3.517154e-01 4.969053e-06 1.734326e-03 2.975928e-01 1.355527e-04 7.003133e-01 5.051541e-01 9.725544e-06 9.049018e-01 2.205418e-01 1.442171e-04 2.630879e-04 5.312689e-01 5.677870e-01 3.815991e-01 3.320813e-01 4.732229e-01 9.989069e-01 1.010057e-03 2.690411e-04 1.234005e-01 1.233279e-05 1.521390e-05 3.199635e-01 5.287805e-01 0.1848360814 3.111321e-01 6.644160e-04 9.958837e-01 6.682696e-01 8.967446e-01 1.945335e-01 7.741294e-01 8.672127e-01 5.746298e-01 8.382938e-01 8.422686e-01 6.982854e-01 6.689637e-01 6.566967e-01 1.538784e-01 7.883977e-01 4.899988e-01 3.357688e-01 1.950176e-01 7.845871e-01 4.931845e-01 9.994438e-01 8.266205e-01 6.827294e-05 4.915137e-02 7.032249e-02 3.196342e-01 2.080413e-01
4         Leptoclinus maculatus 2.561957e-04 0.015055763 1.027233e-04 5.531793e-02 1.521674e-06 1.903466e-05 5.275007e-05 7.018422e-04 0.4434807489 1.051996e-01 2.163078e-03 1.056226e-04 1.587352e-05 7.406232e-06 1.436800e-05 8.506460e-03 2.060949e-02 7.026680e-06 1.943117e-06 1.222702e-02 5.200277e-04 1.280456e-02 8.601783e-07 1.363775e-05 1.433849e-05 4.345814e-03 1.429249e-05 1.967850e-02 3.169398e-03 3.322173e-06 2.327335e-05 1.453173e-06 1.122264e-06 5.837129e-07 1.474386e-05 2.401942e-07 9.485641e-07 3.001678e-06 2.135220e-06 7.728508e-04 1.621803e-06 1.062807e-06 1.884279e-06 6.894775e-07 1.390462e-07 8.862094e-03 2.496710e-02 7.124698e-07 1.713862e-05 2.117176e-05 3.656201e-06 3.860498e-06 4.691901e-06 1.678231e-06 2.539753e-06 0.0002441336 9.964449e-07 3.959043e-05 2.679269e-06 8.790630e-04 1.159694e-07 7.459746e-08 2.178431e-03 1.713989e-06 1.098326e-02 9.078582e-08 5.540548e-05 3.163881e-04 9.272115e-08 4.297976e-03 1.796595e-01 1.622576e-05 4.203757e-03 3.442886e-06 6.304335e-03 1.833768e-06 8.644460e-04 2.583846e-07 1.328969e-06 2.103073e-05 2.198683e-03 3.774797e-02 2.639753e-05 7.580615e-07
5             Mallotus villosus 8.930134e-01 0.787358455 1.859805e-03 2.591198e-04 8.925793e-01 6.824072e-03 2.250365e-04 1.459970e-02 0.0010531645 4.615874e-04 8.441859e-04 3.222864e-02 2.349074e-04 3.630394e-03 3.348361e-04 3.285278e-01 2.236380e-02 3.981701e-05 7.909197e-04 7.312160e-01 9.903438e-01 2.654542e-02 2.146472e-01 9.721276e-01 6.929352e-03 8.280057e-02 3.000622e-03 1.216881e-02 5.191398e-06 1.799329e-05 4.022378e-01 3.565982e-01 2.672907e-01 3.979796e-01 7.791818e-01 2.493714e-04 3.014236e-02 4.882751e-04 4.940570e-04 6.290118e-01 3.182223e-01 8.192994e-01 1.744273e-01 2.489122e-01 2.578007e-01 4.793440e-01 2.385294e-01 2.736994e-04 2.385991e-01 4.214201e-01 3.896219e-01 2.967644e-01 1.102933e-01 2.825985e-04 2.241798e-04 0.6311304718 1.697800e-01 2.235670e-03 1.546334e-03 2.529745e-01 4.925517e-02 7.844455e-01 1.230659e-01 9.145886e-02 5.010363e-04 2.990640e-02 1.035263e-01 2.410178e-01 3.309093e-01 1.014064e-01 2.920106e-01 4.057332e-04 5.898810e-02 1.963567e-03 3.272997e-04 9.424917e-04 1.197773e-01 4.702726e-04 3.820169e-04 4.772537e-03 4.361859e-01 4.516594e-01 8.175746e-03 9.481273e-02
6           Maurolicus muelleri 8.032319e-07 0.001423145 2.181472e-06 9.007992e-06 3.830391e-06 5.718270e-05 1.040940e-04 1.717238e-05 0.0007730306 6.913241e-06 1.027833e-04 2.583772e-05 8.103007e-06 3.167485e-04 4.358388e-06 1.467308e-05 5.444267e-07 2.038215e-05 5.968108e-06 1.380981e-06 1.346934e-03 1.699336e-06 2.887385e-05 1.198794e-03 2.558423e-05 2.789051e-06 4.237332e-05 3.649784e-06 2.785286e-06 1.005037e-05 6.537181e-05 4.476914e-06 2.517978e-06 1.842872e-06 6.142345e-07 4.496078e-07 2.931344e-06 8.982250e-06 6.363111e-06 1.593479e-06 5.205492e-06 3.100496e-06 5.609559e-06 2.052532e-06 3.091778e-07 2.019490e-05 2.616925e-06 1.713673e-06 6.090505e-05 5.191009e-06 1.270176e-06 1.123973e-05 1.388976e-05 5.091115e-06 7.642929e-06 0.0006185237 3.078302e-06 1.097555e-05 6.609791e-06 3.939180e-07 3.457236e-07 2.255042e-07 2.745256e-06 6.159175e-06 3.033178e-06 2.757832e-07 4.555362e-07 1.970108e-07 2.471404e-07 1.157291e-06 3.201054e-06 2.257779e-06 1.654492e-06 1.431788e-04 6.000402e-06 5.498257e-06 8.518181e-06 6.413291e-07 4.059721e-06 6.314281e-05 4.205811e-06 1.555130e-04 6.264312e-06 2.405735e-06
7        Myoxocephalus scorpius 1.338410e-06 0.002169136 9.578157e-05 3.273931e-05 5.770103e-06 9.659547e-05 4.216843e-07 2.577911e-05 0.0009256869 1.904128e-04 1.241480e-04 4.189581e-05 1.404045e-05 3.655739e-05 4.693194e-05 1.656562e-04 1.780461e-05 3.576444e-05 1.004275e-05 2.947553e-05 2.266256e-05 2.812962e-06 4.682660e-06 4.297718e-05 1.428863e-04 1.323204e-04 7.061783e-05 6.216004e-06 5.482900e-05 1.645212e-03 1.050334e-04 9.831812e-05 7.629987e-04 3.267772e-06 9.637124e-05 6.296977e-07 6.167873e-05 1.482057e-05 1.028709e-05 7.787885e-05 8.595114e-06 5.483880e-06 1.630713e-04 3.370083e-06 4.418406e-07 2.692070e-06 6.264618e-05 2.324072e-04 1.104712e-04 8.895387e-06 4.810372e-05 1.861054e-05 3.509389e-04 8.635095e-06 1.279782e-05 0.0009268080 6.795280e-05 1.805314e-05 1.047433e-05 1.709306e-05 7.684650e-06 3.674252e-07 5.060129e-06 3.478430e-05 6.818388e-05 3.682869e-05 2.169302e-05 2.042806e-05 3.770234e-07 1.956126e-06 1.175541e-04 3.590589e-06 7.596444e-05 2.629270e-04 1.366666e-04 8.860927e-06 1.436883e-04 9.032090e-07 6.705388e-06 1.017019e-04 7.165555e-06 9.358030e-06 1.726235e-04 3.807860e-06
8              Pholis gunnellus 6.751268e-04 0.001546276 2.377360e-06 1.033592e-05 1.064967e-01 6.316146e-05 3.198044e-07 1.769394e-05 0.0008070418 1.918013e-01 6.050647e-06 2.844417e-05 8.752500e-06 3.727630e-04 3.015277e-05 2.101245e-04 1.124559e-05 1.626671e-01 6.682164e-06 9.110626e-06 1.663518e-05 1.023280e-01 3.041129e-06 3.416250e-05 3.738400e-02 6.643947e-02 1.605329e-03 8.391164e-02 9.980739e-02 1.213939e-01 7.208768e-05 5.116061e-06 7.260095e-01 5.235489e-05 2.198114e-01 2.994243e-01 3.357020e-06 1.032686e-05 2.680938e-04 7.147583e-03 5.796032e-06 3.608327e-06 1.377318e-01 2.368877e-06 3.604554e-01 1.794093e-02 4.259190e-02 3.310256e-04 3.053898e-02 3.289998e-01 1.075377e-04 3.021040e-01 1.565390e-05 6.690380e-02 8.488079e-06 0.0396595428 3.488557e-06 1.627464e-04 7.710416e-06 3.317620e-03 3.488864e-05 1.016112e-05 5.053742e-03 2.166213e-03 5.464222e-02 2.642165e-05 4.935966e-03 3.274360e-03 3.743676e-05 8.587038e-03 3.474559e-01 2.046812e-01 5.675254e-02 1.209915e-05 3.359434e-02 6.344717e-06 1.351038e-02 6.779100e-07 4.456971e-06 1.220972e-03 2.624830e-02 6.709660e-02 4.516754e-01 2.912287e-02
9         Pleuronectes platessa 7.588736e-07 0.001297922 1.958410e-06 1.446782e-06 3.482287e-06 5.162807e-05 2.977581e-07 1.600356e-05 0.0007237817 6.514519e-06 4.789100e-06 2.344983e-05 7.436298e-06 2.034760e-05 4.231842e-06 2.241652e-06 4.993081e-07 1.984819e-05 5.548882e-06 1.268817e-06 1.444648e-05 1.571445e-06 2.421062e-06 2.843693e-05 2.167081e-06 2.682162e-06 3.909219e-05 3.393483e-06 2.481751e-06 9.170363e-06 6.087723e-05 4.183232e-06 2.249449e-06 1.776866e-06 5.945873e-07 4.331810e-07 2.621067e-06 8.376385e-06 5.832315e-06 1.516902e-06 4.776257e-06 3.046132e-06 5.465611e-06 1.948209e-06 2.961065e-07 1.525727e-06 2.477554e-06 1.632349e-06 4.918313e-06 4.943780e-06 1.137468e-06 1.023334e-05 1.318187e-05 4.939883e-06 7.103873e-06 0.0005618085 2.886178e-06 9.739505e-06 6.452300e-06 3.741268e-07 3.259089e-07 2.105531e-07 2.322348e-07 4.537303e-07 2.784869e-06 2.580865e-07 4.329779e-07 1.841895e-07 2.302153e-07 1.011875e-06 3.124389e-06 2.191548e-06 1.565155e-06 9.872969e-06 5.567747e-06 5.123811e-06 7.901608e-07 5.666649e-07 3.672736e-06 5.804863e-05 4.033025e-06 5.234572e-06 5.785960e-06 2.194508e-06
10              Zz_Gadus morhua 5.130637e-02 0.128875919 4.208621e-04 2.274550e-01 8.920748e-04 9.925963e-01 7.858101e-06 2.800926e-03 0.0034703800 2.593054e-01 4.342704e-01 9.659191e-01 4.715463e-01 9.951648e-01 9.989543e-01 2.928802e-01 7.131470e-02 8.365415e-01 9.990740e-01 2.563864e-01 3.711231e-03 7.195456e-01 7.850701e-01 2.229754e-03 6.903586e-01 3.374696e-01 9.950167e-01 7.420799e-01 7.176747e-01 1.917331e-01 2.454696e-01 6.431710e-01 7.842260e-05 3.043207e-01 6.392279e-05 9.809931e-06 4.645606e-01 9.994193e-01 9.428675e-02 1.422900e-01 6.815870e-01 1.804085e-01 1.563727e-01 1.832819e-01 1.167554e-05 1.615985e-01 2.206103e-01 2.458051e-04 7.294865e-01 2.488395e-01 4.866855e-01 4.007319e-01 8.892361e-01 6.122780e-01 4.709255e-01 0.1398505230 5.189312e-01 9.964630e-01 2.511211e-03 7.445556e-02 5.393346e-02 2.100404e-02 9.552127e-02 3.909399e-02 3.589621e-01 1.316227e-01 4.915856e-02 5.698539e-02 4.924160e-05 2.289484e-01 2.591363e-02 6.334710e-03 2.017905e-01 6.617935e-01 7.643963e-01 2.144202e-01 3.592393e-01 8.070252e-05 1.729613e-01 9.934524e-01 4.861830e-01 3.727875e-01 2.190504e-01 6.678954e-01

4.4 Plot outputs

plot_amp_eff(M4_output)

bar_plot_est_ini_prop(M4_output)

heatmap_plot_est_ini_prop(M4_output)

5 Model 5

5.1 Load the stan model

M5 <- load_model('M5')

5.2 Prepare the data to be loaded in the model.

mock_columns <- metabarcoding %>% select(Mock_1:Mock_6) %>% names()
sample_columns <- metabarcoding %>% select(-all_of(mock_columns),-Species,-sp_idx,-ini_conc) %>% names()

stan_data_M5 <- prep_stan_M5(
    qpcr_data = cod_qpcr,
    sample_type = "Sample_type",
    Ct = "Ct",
    sample_name_column = "Sample_name",
    standard_concentration = "Std_concentration",
    plate_index = 'Plate',
    metabarcoding_data = metabarcoding,
    mock_sequencing_columns = mock_columns,
    sample_sequencing_columns = sample_columns,
    mock_initial_concentration = 'ini_conc',
    species_index = 'sp_idx',
    species_names = 'Species',
    number_of_PCR = 43,
    alpha_magnitude = 0.1)

M5_output <- Run_Model(stan_object = M5, stan_data = stan_data_M5,
                                             treedepth = 12,iterations = 2000,warmup = 1000)

5.3 Extract outputs

extract_amp_efficiecy(M5_output)
                        Species sp_idx        alpha alpha_2.5%_CI alpha_97.5%_CI
1                 Brosme brosme      1 -0.014631604  -0.014744958   -0.014518579
2            Cyclopterus lumpus      2 -0.022597298  -0.022695346   -0.022496063
3  Hippoglossoides platessoides      3 -0.002320093  -0.002410774   -0.002229619
4         Leptoclinus maculatus      4  0.030795620   0.030719541    0.030874331
5             Mallotus villosus      5 -0.017329374  -0.017428054   -0.017232835
6           Maurolicus muelleri      6  0.000786340   0.000701016    0.000875434
7        Myoxocephalus scorpius      7 -0.013591526  -0.013689554   -0.013495651
8              Pholis gunnellus      8 -0.002706435  -0.002809067   -0.002602017
9         Pleuronectes platessa      9  0.002543494   0.002430479    0.002657532
10              Zz_Gadus morhua     10  0.000000000   0.000000000    0.000000000
amp_eff_output_extract(M5_output)
                        Species    Pre-PCR   Post-PCR         ALR Post-PCR_est Post-PCR_est_2.5%_CI Post-PCR_est_97.5%_CI
1                 Brosme brosme 0.08923200 0.05556938  0.01337365   0.05556739           0.05549299            0.05563827
2            Cyclopterus lumpus 0.17871590 0.07901771  0.70793133   0.07901434           0.07896050            0.07907503
3  Hippoglossoides platessoides 0.10093796 0.10672923  0.13663999   0.10672526           0.10668632            0.10675782
4         Leptoclinus maculatus 0.05519582 0.24240363 -0.46697893   0.24240614           0.24246990            0.24235749
5             Mallotus villosus 0.14545023 0.08065732  0.50196793   0.08065548           0.08059832            0.08070113
6           Maurolicus muelleri 0.10501282 0.12690236  0.17621634   0.12690145           0.12688438            0.12693264
7        Myoxocephalus scorpius 0.13199579 0.08596141  0.40490397   0.08595726           0.08589876            0.08600346
8              Pholis gunnellus 0.06633870 0.06898988 -0.28309260   0.06898662           0.06892602            0.06904906
9         Pleuronectes platessa 0.03907419 0.05093104 -0.81240387   0.05092471           0.05085726            0.05099189
10              Zz_Gadus morhua 0.08804659 0.10283804  0.00000000   0.10286134           0.10322553            0.10249321
extract_ini_prop(M5_output)
                        Species   2019629_11   2019629_12   2019629_13   2019629_14   2019629_15   2019629_16   2019629_19   2019629_20   2019629_21   2019629_22   2019629_23   2019629_24   2019629_27   2019629_28   2019629_29    2019629_3   2019629_30   2019629_31   2019629_32    2019629_4    2019629_5    2019629_6    2019629_7    2019629_8   2020620_03   2020620_04   2020620_05   2020620_06   2020620_07   2020620_08   2020620_11   2020620_12   2020620_13   2020620_14   2020620_15   2020620_16   2020620_19   2020620_20   2020620_21   2020620_22   2020620_23   2020620_24   2020620_27   2020620_28   2020620_29   2020620_30   2020620_31   2020620_32   2021624_10   2021624_11   2021624_14   2021624_15   2021624_16   2021624_17   2021624_18   2021624_19   2021624_20   2021624_21   2021624_22   2021624_25   2021624_26   2021624_27   2021624_28   2021624_29    2021624_3   2021624_30   2021624_31   2021624_32   2021624_33   2021624_36   2021624_37   2021624_38   2021624_39    2021624_4   2021624_40   2021624_41   2021624_42   2021624_43   2021624_44    2021624_5    2021624_6    2021624_7    2021624_8    2021624_9
1                 Brosme brosme 8.967006e-07 0.0012129693 1.095544e-06 1.933121e-05 3.910267e-06 0.0010545735 3.836614e-07 2.413380e-05 0.0009075262 1.125369e-05 7.861081e-04 0.0046853394 1.555850e-05 1.935977e-04 7.394896e-05 7.164676e-05 7.943307e-07 2.497813e-03 1.847778e-04 2.330274e-06 6.552982e-04 5.704151e-06 5.980806e-04 2.128535e-05 1.343341e-04 9.313706e-02 0.0006277746 2.699025e-04 9.554051e-06 1.496325e-05 8.263163e-05 2.269635e-04 2.710064e-06 5.443892e-05 1.445696e-06 8.889559e-07 1.037039e-04 1.259323e-04 7.942634e-06 4.327892e-05 1.551800e-05 4.060084e-06 7.045795e-06 3.078106e-06 7.300359e-07 4.178932e-05 4.412749e-06 1.280137e-06 1.554798e-05 4.576797e-06 2.159200e-04 4.855877e-04 9.693127e-05 7.802607e-04 1.060071e-05 2.821003e-04 1.278789e-04 0.0005193637 3.531767e-06 9.100670e-06 3.502075e-07 5.292354e-06 5.581889e-06 2.411796e-05 4.153098e-06 3.068978e-05 5.423343e-07 8.617101e-06 1.903049e-07 3.017801e-05 4.803386e-06 2.528654e-06 2.302753e-06 2.443339e-05 2.309305e-05 7.872903e-06 7.132588e-05 4.043953e-07 5.250127e-06 0.0022410472 7.716293e-06 5.837700e-06 2.141539e-04 1.300683e-04
2            Cyclopterus lumpus 2.876068e-05 0.0016240417 5.321032e-04 1.780099e-04 4.045156e-06 0.0012117328 5.898212e-05 4.836324e-03 0.0011558000 3.344305e-04 1.946671e-03 0.0029687378 2.195033e-04 2.343608e-04 9.898059e-04 9.877778e-04 8.798564e-01 1.222131e-04 2.309239e-04 5.288324e-05 2.596938e-05 7.225976e-06 1.471202e-05 1.837767e-02 3.961552e-04 1.272476e-04 0.0009041058 3.713012e-04 4.855328e-04 1.827415e-05 1.040619e-04 1.706352e-05 4.157867e-03 4.145989e-06 6.978940e-04 1.005653e-06 8.166689e-06 1.690872e-04 1.096471e-05 1.267222e-04 2.187366e-05 5.818763e-06 8.819347e-06 3.961005e-06 1.375738e-04 1.254471e-04 5.735650e-06 1.396908e-06 5.218386e-04 5.278014e-04 3.829305e-06 1.669235e-05 1.204962e-04 3.430125e-04 1.462614e-05 3.468437e-04 9.183088e-06 0.0225348489 4.178398e-06 8.162489e-05 2.285468e-05 3.032439e-07 4.082038e-05 6.611079e-07 3.026666e-04 9.679954e-05 3.269858e-05 9.669451e-05 3.687233e-05 4.170395e-05 9.707854e-04 1.495211e-04 2.314495e-01 2.829889e-05 6.566688e-04 1.012360e-05 1.933621e-02 4.677903e-07 7.283842e-06 0.0026526491 9.750908e-06 2.933216e-04 1.345384e-03 1.837306e-04
3  Hippoglossoides platessoides 5.739039e-02 0.0608579811 9.974280e-01 8.807176e-01 2.670214e-06 0.0006828956 9.995582e-01 9.779326e-01 0.5488227319 5.604816e-01 9.487313e-01 0.0028122115 9.090751e-01 2.456222e-03 8.663316e-03 4.941434e-01 5.921934e-02 6.270411e-05 2.225766e-03 1.063001e-04 3.346533e-03 4.512694e-01 2.337275e-04 5.579966e-03 7.705792e-01 6.427756e-01 0.0004659416 5.059300e-01 5.557630e-01 8.094117e-01 4.504750e-01 8.179965e-06 1.706173e-03 4.085603e-01 1.378469e-04 7.002371e-01 8.708536e-01 8.234139e-05 9.810071e-01 2.473509e-01 3.723906e-04 3.141661e-04 6.197158e-01 6.730337e-01 3.816628e-01 3.770221e-01 5.680971e-01 9.991697e-01 3.469707e-03 3.467679e-04 2.113126e-01 8.035772e-06 5.937606e-05 6.637955e-01 9.878405e-01 2.151591e-01 5.887487e-01 0.0428806861 9.983349e-01 7.134420e-01 9.462829e-01 1.984028e-01 8.390341e-01 9.004436e-01 8.857323e-01 9.514549e-01 8.818744e-01 7.391879e-01 6.689813e-01 8.156606e-01 1.557590e-01 7.923393e-01 6.027002e-01 9.557865e-01 6.806511e-01 9.725000e-01 7.220616e-01 9.995220e-01 9.731480e-01 0.0016124899 9.324126e-02 1.113490e-01 4.071322e-01 5.970444e-01
4         Leptoclinus maculatus 2.689101e-04 0.0153132020 1.004389e-04 6.796009e-02 1.026312e-06 0.0002242307 5.172031e-05 6.964284e-04 0.4408754983 1.331288e-01 3.650256e-03 0.0006989048 2.422781e-05 3.782642e-05 2.205147e-04 1.139088e-02 2.185257e-02 2.073175e-05 3.422866e-05 1.559802e-02 5.267729e-04 4.161348e-02 2.289206e-06 6.957394e-06 4.005925e-05 6.278327e-03 0.0001485815 7.013551e-02 9.829890e-03 2.912698e-06 1.883273e-05 2.542786e-06 1.109737e-06 6.551099e-07 1.568642e-05 2.631290e-07 1.146027e-06 2.663345e-05 1.776963e-06 8.674419e-04 3.318491e-06 8.554592e-07 1.626191e-06 6.249017e-07 2.209326e-07 1.006116e-02 2.998109e-02 3.793550e-07 5.448739e-05 2.564116e-05 5.995772e-06 2.667971e-06 1.830226e-05 2.785160e-06 2.334833e-06 8.881951e-05 1.277675e-06 0.0024114850 1.036473e-06 9.391363e-04 7.343476e-08 4.946484e-08 2.362143e-03 1.684788e-06 1.693529e-02 7.378815e-08 5.798902e-05 3.349653e-04 5.565739e-08 5.341730e-03 1.817515e-01 1.579653e-05 5.172788e-03 5.349002e-06 2.199996e-02 1.517757e-06 1.266022e-03 1.238066e-07 1.107634e-06 0.0005244148 4.173796e-03 5.983528e-02 3.115398e-05 1.335958e-06
5             Mallotus villosus 9.368075e-01 0.8898296752 1.829666e-03 3.162481e-04 8.931109e-01 0.1387627466 2.219917e-04 1.452243e-02 0.0011442478 5.738871e-04 1.404503e-03 0.2208662140 3.879167e-04 2.544026e-02 5.349843e-03 4.400208e-01 2.370315e-02 1.125413e-04 2.270553e-02 9.326666e-01 9.915247e-01 8.629721e-02 7.765082e-01 9.744186e-01 2.010672e-02 1.197999e-01 0.0511278272 4.328755e-02 1.104479e-05 1.618517e-05 5.152182e-01 8.235278e-01 2.672807e-01 5.463668e-01 7.790727e-01 2.542779e-04 5.196825e-02 6.088696e-03 5.272598e-04 7.053541e-01 8.409722e-01 9.812068e-01 2.033695e-01 2.950453e-01 2.577163e-01 5.444179e-01 2.864356e-01 2.520507e-04 8.270049e-01 5.593781e-01 6.672848e-01 4.909888e-01 7.324412e-01 5.746004e-04 3.750888e-04 7.357558e-01 3.212092e-01 0.1450323317 1.518696e-03 2.700876e-01 5.198422e-02 8.000994e-01 1.333819e-01 9.495179e-02 7.632811e-04 3.394288e-02 1.084069e-01 2.551243e-01 3.309370e-01 1.259754e-01 2.955576e-01 4.059735e-04 7.258157e-02 5.543729e-03 1.108557e-03 1.156875e-03 1.753797e-01 4.667047e-04 4.428147e-04 0.2716639204 8.279245e-01 7.157816e-01 1.039995e-02 2.721381e-01
6           Maurolicus muelleri 5.844167e-07 0.0008207730 6.899277e-07 1.015280e-05 2.762734e-06 0.0006655006 1.022525e-04 1.591356e-05 0.0007775952 6.520938e-06 1.685898e-04 0.0001206815 9.424295e-06 2.178889e-03 4.767476e-05 1.836790e-05 4.208536e-07 5.986269e-05 1.026471e-04 1.302560e-06 1.391624e-03 3.498726e-06 1.004414e-04 1.093920e-03 7.078541e-05 2.710832e-06 0.0004222615 7.143856e-06 5.584703e-06 8.832857e-06 4.561540e-05 7.183098e-06 2.091894e-06 1.920820e-06 8.700580e-07 5.576641e-07 3.588900e-06 7.172122e-05 5.021541e-06 1.456517e-06 9.635254e-06 2.618661e-06 4.116416e-06 1.763599e-06 5.118636e-07 2.222542e-05 2.427417e-06 8.770693e-07 1.966258e-04 2.837955e-06 1.601592e-06 7.624820e-06 5.346192e-05 7.673343e-06 5.521880e-06 1.940369e-04 4.058084e-06 0.0003285067 2.381234e-06 3.089394e-07 2.009108e-07 1.572076e-07 2.882327e-06 5.938497e-06 2.398694e-06 2.184485e-07 3.280691e-07 1.143155e-07 1.249009e-07 1.078520e-06 2.896206e-06 1.590311e-06 1.317321e-06 3.735338e-04 1.381102e-05 4.450464e-06 1.182906e-05 2.600098e-07 3.238539e-06 0.0013792899 4.230940e-06 2.333411e-04 3.393696e-06 3.842940e-06
7        Myoxocephalus scorpius 9.101099e-07 0.0011182147 8.242906e-05 3.854880e-05 4.082166e-06 0.0009820363 3.543072e-07 2.404208e-05 0.0009872211 2.350018e-04 1.952247e-04 0.0001918023 1.422259e-05 1.746646e-04 6.887558e-04 2.186216e-04 1.819368e-05 9.925812e-05 1.580347e-04 3.552952e-05 1.898388e-05 5.775418e-06 1.080869e-05 2.464592e-05 4.084809e-04 1.858741e-04 0.0006519007 1.255398e-05 1.610588e-04 1.920602e-03 6.829329e-05 2.206554e-04 7.496036e-04 3.051313e-06 1.010235e-04 8.037770e-07 1.002910e-04 1.255422e-04 7.945340e-06 8.582380e-05 1.409214e-05 3.803005e-06 1.780893e-04 2.878624e-06 6.979362e-07 2.453201e-06 7.262331e-05 2.208217e-04 3.567292e-04 4.282730e-06 8.111772e-05 1.252432e-05 2.172652e-03 1.308388e-05 9.635937e-06 2.661909e-04 1.209895e-04 0.0005203632 3.772176e-06 1.788172e-05 7.371609e-06 2.299097e-07 5.301923e-06 3.552107e-05 9.783212e-05 4.169674e-05 2.224034e-05 2.141013e-05 1.825250e-07 1.763599e-06 1.170995e-04 2.413633e-06 9.105372e-05 7.048673e-04 4.488256e-04 7.132925e-06 2.097949e-04 3.796653e-07 5.162747e-06 0.0021187744 7.085709e-06 5.673486e-06 1.977738e-04 6.048539e-06
8              Pholis gunnellus 7.076216e-04 0.0009456781 8.598709e-07 1.182002e-05 1.066019e-01 0.0006762027 2.922217e-07 1.566512e-05 0.0009130801 2.427589e-01 6.023217e-06 0.0001313947 1.045535e-05 2.526047e-03 4.441982e-04 2.778008e-04 1.156686e-05 7.014954e-01 1.107741e-04 1.105030e-05 1.484005e-05 3.327538e-01 8.021127e-06 1.715563e-05 1.087296e-01 9.605892e-02 0.0272858208 2.990622e-01 3.096535e-01 1.432877e-01 6.010040e-05 8.532646e-06 7.260444e-01 6.955627e-05 2.197965e-01 2.994882e-01 3.650188e-06 8.866764e-05 2.873681e-04 8.012465e-03 1.000492e-05 2.696359e-06 1.606414e-01 2.066819e-06 3.604406e-01 2.038143e-02 5.113425e-02 3.215155e-04 1.057772e-01 4.366707e-01 1.827373e-04 4.996586e-01 6.205494e-05 1.388464e-01 6.779841e-06 4.325677e-02 4.723128e-06 0.0097838848 2.518046e-06 3.542134e-03 3.663104e-05 1.018562e-05 5.478038e-03 2.249247e-03 8.423533e-02 2.973658e-05 5.170650e-03 3.465892e-03 3.671393e-05 1.066642e-02 3.516772e-01 2.057434e-01 6.979290e-02 1.636960e-05 1.172001e-01 5.005682e-06 1.977440e-02 2.781464e-07 3.586808e-06 0.0669348900 4.979898e-02 1.064078e-01 5.752444e-01 8.361752e-02
9         Pleuronectes platessa 4.998847e-07 0.0007725841 6.358649e-07 1.281154e-06 2.490044e-06 0.0005788678 2.389041e-07 1.362426e-05 0.0007799615 6.023352e-06 5.160377e-06 0.0001099071 8.577734e-06 1.065092e-04 4.599574e-05 2.140024e-06 4.041971e-07 5.973906e-05 9.241640e-05 1.231583e-06 1.308120e-05 2.973059e-06 5.911998e-06 1.509969e-05 3.914692e-06 2.493976e-06 0.0003819143 7.679495e-06 5.053069e-06 8.019460e-06 4.857133e-05 6.762611e-06 1.885416e-06 1.652984e-06 8.343611e-07 5.416740e-07 3.183750e-06 7.355250e-05 4.379556e-06 1.343084e-06 9.034179e-06 2.417544e-06 3.726547e-06 1.710067e-06 5.089265e-07 1.313446e-06 2.325798e-06 7.709099e-07 8.533543e-06 2.607143e-06 1.559771e-06 7.454855e-06 5.111724e-05 7.667578e-06 6.093343e-06 1.787826e-04 3.771271e-06 0.0003182871 2.335623e-06 2.928548e-07 1.905384e-07 1.457986e-07 2.116912e-07 2.726074e-07 2.315991e-06 2.055224e-07 3.058623e-07 1.166571e-07 1.185854e-07 1.019742e-06 2.593379e-06 1.424444e-06 1.257770e-06 1.400668e-05 1.269846e-05 4.322647e-06 8.993953e-07 2.425042e-07 3.107494e-06 0.0011917008 3.944682e-06 3.580014e-06 3.176491e-06 3.562407e-06
10              Zz_Gadus morhua 4.793890e-03 0.0275048808 2.406233e-05 5.074688e-02 2.662958e-04 0.8551612134 5.546743e-06 1.918846e-03 0.0036363379 6.246347e-02 4.310617e-02 0.7674148069 9.023501e-02 9.666516e-01 9.834759e-01 5.286857e-02 1.533718e-02 2.954697e-01 9.741549e-01 5.152480e-02 2.482175e-03 8.804095e-02 2.225178e-01 4.447456e-04 9.953074e-02 4.163192e-02 0.9179838721 8.091621e-02 1.240758e-01 4.531079e-02 3.387871e-02 1.759743e-01 5.348567e-05 4.493748e-02 1.752350e-04 1.638915e-05 7.695444e-02 9.931478e-01 1.814021e-02 3.815645e-02 1.585719e-01 1.845674e-02 1.606986e-02 3.190491e-02 4.008237e-05 4.792425e-02 6.426440e-02 3.118515e-05 6.259437e-02 3.036660e-03 1.209099e-01 8.812039e-03 2.649244e-01 1.956290e-01 1.172885e-02 4.471592e-03 8.977014e-02 0.7756702428 1.266664e-04 1.187999e-02 1.665246e-03 1.481454e-03 1.968902e-02 2.287118e-03 1.192444e-02 1.440284e-02 4.433878e-03 1.759976e-03 7.480929e-06 4.228014e-02 1.415659e-02 1.338016e-03 1.820714e-02 3.750287e-02 1.778852e-01 2.630267e-02 6.188820e-02 9.135423e-06 2.638049e-02 0.6496808235 2.482876e-02 6.084514e-03 5.428423e-03 4.687145e-02
extract_ini_conc(M5_output)
# A tibble: 840 × 5
   Species       Sample      Conc `Conc_2.5%CI` `Conc_97.5%CI`
   <chr>         <chr>      <dbl>         <dbl>          <dbl>
 1 Brosme brosme 2019629_11 -8.58         -14.1         -5.15 
 2 Brosme brosme 2019629_12 -3.12         -10.9          2.28 
 3 Brosme brosme 2019629_13 -3.09         -10.8          2.20 
 4 Brosme brosme 2019629_14 -7.87         -10.6         -5.79 
 5 Brosme brosme 2019629_15 -4.22         -11.5          0.553
 6 Brosme brosme 2019629_16 -6.70         -12.6         -3.10 
 7 Brosme brosme 2019629_19 -2.67         -10.5          3.09 
 8 Brosme brosme 2019629_20 -4.38         -11.4          0.451
 9 Brosme brosme 2019629_21 -1.39         -10.5          6.25 
10 Brosme brosme 2019629_22 -8.62         -13.6         -5.22 
# ℹ 830 more rows

5.4 Plot outputs

plot_amp_eff(M5_output)

bar_plot_est_ini_prop(M5_output)

heatmap_plot_est_ini_prop(M5_output)

plot_est_ini_conc(M5_output)

Guri et al., 2024 that are used in this script.

6 All functions

For step 1:
load_model(model)

For step 2:
prep_stan_M1(...)
prep_stan_M2(...)
prep_stan_M3(...)
prep_stan_M4(...)
prep_stan_M5(...)

For step 3:
Run_Model(stan_object, stan_data)

For step 4:
extract_qpcr_param(model_output)
extract_est_conc(model_output)
extract_amp_efficiecy(model_output)
amp_eff_output_extract(model_output)
extract_ini_prop(model_output)
extract_ini_conc(M5_output)

For step 5:
plot_qpcr_prob_det(model_output,xmin_log, xmax_log)
plot_qpcr_cont_mod(model_output,xmin_log, xmax_log)
plot_qpcr_curves(model_output, xmin_log, xmax_log
plot_qpcr_cont_mod_plate_specific(model_output, xmin_log, xmax_log)
plot_est_conc(model_output)
plot_amp_eff(model_output)
bar_plot_est_ini_prop(model_output)
heatmap_plot_est_ini_prop(model_output)
plot_est_ini_conc(model_output, k = 2)
diagnose_model()